﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ElementumForever.Interfaces;
using ElementumForever.Decorators;
using ElementumForever.Utility;

namespace ElementumForever.Editer
{
    class ItemGroupScene : BaseScene, IMouseControl
    {
        ItemMenuScene menu;
        SelectionManager _selectionManager;

        public ItemGroupScene(ItemMenuScene menu) : base(menu.MainGame) {
            this.menu = menu;
            Initialize(menu.MainGame);
            OnCreat();
        }

        protected override void Initialize(MainGame game)
        {
            base.Initialize(game);
            Width = menu.Width * 0.95f;
            Height = menu.Height * 0.95f;
            Center = new Vector2(350, 225);
            OriginX = Width / 2;
            OriginY = Height / 2;
            Color = Color.WhiteSmoke;
            Alpha = 0.5f;
        }

        public override void OnCreat()//place items here
        {
            base.OnCreat();
            _selectionManager = new SelectionManager();
            _selectionManager.OnSelectEntity += this.menu.SelectItem;
            RectangleShape item = new RectangleShape();
            item.OnCreat();
            AttachChild(item);
            item.Width = 50;
            item.Height = 50;           
            item.Name = "itemPrototype";
            item.X = 30;
            item.Y = 30;
            item.Color = Color.Green;
            item.OriginX = item.Width / 2;
            item.OriginY = item.Height / 2;
            item.ScaleX = 1;
            item.ScaleY = 1;
            item.Rotation = 0;

            _selectionManager.AddEntityDecorator(new SelectDecorator(item));


        }

        public override void OnDraw(GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            base.OnDraw(gameTime, spriteBatch);
            _selectionManager.OnDraw(gameTime, spriteBatch);
        }

        public override void OnUpdate(GameTime gameTime)
        {
            base.OnUpdate(gameTime);
            _selectionManager.OnUpdate(gameTime);
        }

        public void OnMouseClick(Microsoft.Xna.Framework.Input.MouseState state)
        {
            //state = UnitHelper.GetMouseStateInScene(this);
            _selectionManager.OnMouseClick(state);
        }

        public void OnMouseDown(Microsoft.Xna.Framework.Input.MouseState state)
        {
            _selectionManager.OnMouseDown(state);
        }

        public void OnMouseUp(Microsoft.Xna.Framework.Input.MouseState state)
        {
            _selectionManager.OnMouseUp(state);
        }

        public void OnMouseMove(Microsoft.Xna.Framework.Input.MouseState state)
        {
            _selectionManager.OnMouseMove(state);
        }
    }
}
